package com.woniuxy.project.campus.account.dto;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PageInfo<T> {
    private int total;
    private int pages;
    private int pageNum;
    private int pageSize;
    private List<T> list;
    //空参构造方法


    public PageInfo() {
    }

    public PageInfo(Page<?> page, Class<T> cc){
        this.setPageNum((int)page.getCurrent());
        this.setPageSize((int)page.getSize());
        this.setTotal((int)page.getTotal());
        this.setPages((int)page.getPages());
        List<?> records = page.getRecords();
        ArrayList<T> list = new ArrayList<>();
        for (Object source : records){
            T bean = BeanUtil.toBean(source, cc);
            list.add(bean) ;
        }
        this.setList(list);

    }}
